// Ellipse.cpp: implementation of the CEllipse class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Ellipse.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#include "EllipseProperties.h"
#include "resourcemakeDlg.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//IMPLEMENT_DYNAMIC(CEllipse,CObject)
IMPLEMENT_SERIAL(CEllipse,CObject,1)

CEllipse::CEllipse()
{
	m_Type = 3;
	LineWidth = 1;
	m_bFill = 1;
	BrushColor = RGB(255,255,255);

	startX=30;
	startY=21;
	endX=30+52*(CDrawElement::dscrx*4/3);
	endY=21+52*(CDrawElement::dscry*4/3);

}

CEllipse::~CEllipse()
{
	
}

void CEllipse::Serialize(CArchive & ar)
{
	CObject::Serialize(ar);
    if(ar.IsLoading())
    {
    }
	else
	{
    }
}

void CEllipse::ShowProperties()
{
	CEllipseProperties* prop=((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->m_ellipsePropDlg;
	prop->m_pCurrObj = this;
	

	prop->m_LineWidth.Format("%d",this->LineWidth);
	((CComboBox*)prop->GetDlgItem(IDC_LINEWIDTH))->SetCurSel(LineWidth-1);

	prop->m_LineColor = LineColor;
	CString str;
	str.Format("%d:%d:%d",GetRValue(LineColor),GetGValue(LineColor),GetBValue(LineColor));
	((CButton*)prop->GetDlgItem(IDC_BUTTON_COLOR))->SetWindowText(str);
	
	prop->m_BrushColor = BrushColor;
	str.Format("%d:%d:%d",GetRValue(BrushColor),GetGValue(BrushColor),GetBValue(BrushColor));
	((CButton*)prop->GetDlgItem(IDC_BUTTON_BRUSHCOLOR))->SetWindowText(str);

	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_pCurrPropDlg->ShowWindow(FALSE);
	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_pCurrPropDlg=prop;


//	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->iPage=0;
//  ((CResourcemakeDlg*)AfxGetApp()->m_pMainWnd)->m_probasedlg->pDialogpro[1] = ((CResourcemakeDlg*)AfxGetApp()->m_pMainWnd)->m_pCurrPropDlg;
	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->pDialogpro[((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->ipage]->ShowWindow(SW_HIDE);
    ((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->ipage = 3;
	((CTabCtrl*)((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->GetDlgItem(IDC_TAB2))->SetCurSel(3);
	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_pCurrPropDlg->ShowWindow(SW_SHOW);
//	((CTabCtrl*)((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->GetDlgItem(IDC_TAB2))->SetCurSel(1);
//	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->m_paneTree->ShowWindow(FALSE);
//	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_pCurrPropDlg->ShowWindow(TRUE);
//	((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->ipage=1;
//	((CTabCtrl*)((CResourcemakeDlg *)AfxGetApp()->m_pMainWnd)->m_probasedlg->GetDlgItem(IDC_TAB2))->SetCurSel(1);
}

void CEllipse::Draw(CDC *pDC)
{
	CPen cMyPen;
	CPen* pOldPen;
	
//	cMyPen.CreatePenIndirect(&this->MyPen);
	cMyPen.CreatePen(LineStyle,LineWidth,LineColor);
	pOldPen=pDC->SelectObject(&cMyPen);
	
	CBrush* cMyBrush;
	CBrush* pOldBrush;
	
	//cMyBrush.CreateBrushIndirect(&this->MyBrush);
	if(m_bFill)
	{
		cMyBrush=new CBrush;
		cMyBrush->CreateSolidBrush(BrushColor);
	}
	else
		cMyBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
	pOldBrush=pDC->SelectObject(cMyBrush); 
	
	pDC->Ellipse(this->startX,this->startY,this->endX,this->endY); 	
	pDC->SelectObject(pOldPen);
	pDC->SelectObject(pOldBrush); 
}
//*****************************************

////pos="top:left:bottom:right"
//DEL CString CEllipse::getPosStr()
//DEL {
//DEL 	CString str="";
//DEL 	CString strTmp;
//DEL 	int tmp=0;
//DEL 	tmp=startX*TRAN_PROP+0.5;
//DEL 	strTmp.Format("%d:",tmp);//top
//DEL 	str+=strTmp;
//DEL 	tmp=startY*LENG_PROP+0.5;
//DEL 	strTmp.Format("%d:",tmp);//left
//DEL 	str+=strTmp;
//DEL 	tmp=(endX-startX)*TRAN_PROP+0.5;
//DEL 	strTmp.Format("%d:",tmp);//bottom
//DEL 	str+=strTmp;
//DEL 	tmp=(endY-startY)*LENG_PROP+0.5;
//DEL 	strTmp.Format("%d",tmp);//right
//DEL 	str+=strTmp;
//DEL 	//str+="\"";
//DEL 	return str;
//DEL }

//style="width:color:fill-flag:fill-color"
CString CEllipse::getStyle()
{
	CString str="";
	CString strTmp;
	strTmp.Format("%d:",LineWidth);//width
	str+=strTmp;
	strTmp.Format("(254,%d,%d,%d):",GetRValue(LineColor),GetGValue(LineColor),GetBValue(LineColor));
	str+=strTmp;
	if(m_bFill)
	{
		str+="1:";
		strTmp.Format("(254,%d,%d,%d):",GetRValue(BrushColor),GetGValue(BrushColor),GetBValue(BrushColor));
		str+=strTmp;
	}
	else
	{
		str+="0:";
	}
	//str+="\"";
	return str;
}
//*****************************************
void CEllipse::parseStyleStr(CString str)
{
	vector<CString> vec = DStrSlp(str,":");
	int i=0;
	for(vector<CString>::iterator ite=vec.begin();ite!=vec.end();ite++)
	{
		i++;
		if(i==1)
		{
			LineWidth = atoi(*ite);
		}
		else if(i==2)
		{
			LineColor = parseColorStr(*ite);
		}
		else if(i==3)
		{
			int tmp = atoi(*ite);
			if(tmp==0)
			{
				m_bFill = FALSE;
			}
			else{
				m_bFill = TRUE;
			}
		}
		else if(i==4)
		{
			if(m_bFill)
			{
				BrushColor = parseColorStr(*ite);
			}
		}
		else if(i==5)
		{
			//if(m_bFill){
			//	BrushColor = parseColorStr(*ite);
			//}
		}
	}
}
